package edu.uts.reekie.designer.conceptual.model;

import org.eclipse.swt.graphics.Image;

import edu.uts.reekie.designer.ImageHelper;
import edu.uts.reekie.designer.model.Multiple;
import edu.uts.reekie.designer.model.Nameable;
import edu.uts.reekie.designer.model.ViewNode;


public class ViewComponent 
	extends ViewNode 
	implements Nameable, Multiple
{
	
	// properties
	public static String PROPERTY_NAME = "name";
	public static String PROPERTY_STEREOTYPE_PREFIX = "stereotype";
	public static String PROPERTY_STEREOTYPE_REAL_TIME = PROPERTY_STEREOTYPE_PREFIX+" realtime";
	public static String PROPERTY_STEREOTYPE_PRESENTATION = PROPERTY_STEREOTYPE_PREFIX+" presentation";
	public static String PROPERTY_STEREOTYPE_PERSISTENCE = PROPERTY_STEREOTYPE_PREFIX+" persistence";
	public static String PROPERTY_MULTIPLICITY = "multiplicity";
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1;

	private static Image ICON = ImageHelper.createFromConceptualModelResource( "icons/plain16.gif");  //$NON-NLS-1$
	
	private static int count;
	
	public ViewComponent() {
		super();
		
		// set some default values
		setName("component"); 
	}
	
	private boolean isRealTime = false;
	
	
	public boolean isRealTime() {
		return isRealTime;
	}

	public void setRealTime(boolean isRealTime) {
		if (this.isRealTime==isRealTime){
			return;
		}
		this.isRealTime = isRealTime;
		firePropertyChange(PROPERTY_STEREOTYPE_REAL_TIME,new Boolean( !isRealTime), new Boolean(isRealTime)); //$NON-NLS-2$//$NON-NLS-1$
	}

	private boolean isPresentation = false;
	
	public boolean isPresentation() {
		return isPresentation;
	}

	public void setPresentation(boolean isPresentation) {
		if (this.isPresentation==isPresentation){
			return;
		}
		this.isPresentation = isPresentation;
		firePropertyChange(PROPERTY_STEREOTYPE_PRESENTATION, new Boolean(!isPresentation), new Boolean(isPresentation)); //$NON-NLS-2$//$NON-NLS-1$
	}


	private boolean isPersistence = false;
	
	public boolean isPersistence() {
		return isPersistence;
	}

	public void setPersistence(boolean isPersistence) {
		if (this.isPersistence==isPersistence){
			return;
		}
		this.isPersistence = isPersistence;
		firePropertyChange(PROPERTY_STEREOTYPE_PERSISTENCE, new Boolean(!isPersistence), new Boolean(isPersistence)); //$NON-NLS-2$//$NON-NLS-1$
	}

	

	
	private String name;
	
	/* (non-Javadoc)
	 * @see edu.uts.reekie.designer.model.Nameable#getName()
	 */
	public String getName(){
		return name;
	}
	
	/* (non-Javadoc)
	 * @see edu.uts.reekie.designer.model.Nameable#setName(java.lang.String)
	 */
	public void setName(String name){
		this.name = name;
		firePropertyChange(PROPERTY_NAME, null, name); //$NON-NLS-2$//$NON-NLS-1$
		
	}
	
	private boolean isMultiple = false;
	
	public boolean isMultiple() {
		return isMultiple;
	}
	
	public void setMultiple(boolean isMul){
		if (this.isMultiple==isMul){
			return;
		}
		this.isMultiple = isMul;
		firePropertyChange(PROPERTY_MULTIPLICITY, new Boolean(!isMultiple), new Boolean(isMultiple)); //$NON-NLS-2$//$NON-NLS-1$
	}
	
	
	public Image getIconImage() {
		return ICON;
	}

	protected String getNewID() {
		return Integer.toString(count++);
	}

	public String toString() {
		return "Component \"" + name + "\""; 
	}
	
	
}
